function MyWorker() {
  this.worker = null
}

MyWorker.prototype.getWorker = function(){
  if(!this.worker) {
    this.worker = new Worker('/worker/worker.js')
  }
  return this.worker
}

MyWorker.prototype.executeFunc = function(params) {
  this.worker.postMessage(params)
  const promise = new Promise((resolve, reject) => {
    this.worker.addEventListener('message', e => {
      resolve(e.data)
    })
  })
  return promise
}

const myWorker = new MyWorker()
myWorker.getWorker()
console.log('初始化worker')
export default myWorker